package com.boot.mgt.service.impl

import com.boot.core.result.ResultTo
import com.boot.mgt.dao.mysql.TaAccidentImageMapper
import com.boot.mgt.model.TaAccidentImage
import com.boot.mgt.service.TaAccidentImageService
import com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImpl
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import java.util.*

@AutoJsonRpcServiceImpl
@Service
class TaAccidentImageServiceImpl : TaAccidentImageService {


    @Autowired
    protected lateinit var accidentImageServiceMapper: TaAccidentImageMapper

    companion object {
        private val log: Logger = LoggerFactory.getLogger(this::class.java)
    }

    override fun insert(taAccidentImage: TaAccidentImage): ResultTo {
        taAccidentImage.addTime = Date()
        accidentImageServiceMapper.insertSelective(taAccidentImage)
        return ResultTo().setData("id", taAccidentImage.id!!)
    }

    override fun selectById(id: Int): ResultTo {
        val image = accidentImageServiceMapper.selectByPrimaryKey(id)
        return ResultTo().setData("image", Optional.ofNullable(image).orElse(TaAccidentImage()))
    }

    override fun delete(id: Int): ResultTo {
        accidentImageServiceMapper.deleteByPrimaryKey(id)
        return ResultTo()
    }
}